package com.wyd.rabbitmq.config;

import org.springframework.amqp.core.Binding;
import org.springframework.amqp.core.BindingBuilder;
import org.springframework.amqp.core.DirectExchange;
import org.springframework.amqp.core.Queue;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;

/**
 * Created with IntelliJ IDEA.
 *
 * @Auther: 雷哥
 * @Date: 2020/10/07/23:27
 * @Description:
 */
@Configuration
public class RoutingDirectConfig {

  /**
   * 声明交换机
   */
  @Bean
  public DirectExchange directExchange(){
    DirectExchange directExchange=new DirectExchange("directs");
    return directExchange;
  }

  /**
   * 声明队列1
   */
  @Bean
  public Queue queue1(){
    return new Queue("queue1");
  }

  /**
   * 声明队列2
   */
  @Bean
  public Queue queue2(){
    return new Queue("queue2");
  }

  /**
   * 把队列1绑定到交换机里面并指定队列的路由key为info
   */
  @Bean
  public Binding binding11(){
    Binding binding= BindingBuilder.bind(queue1())
        .to(directExchange()).with("info");
    return binding;
  }
  /**
   * 把队列1绑定到交换机里面并指定队列的路由key为warm
   */
  @Bean
  public Binding binding12(){
    Binding binding= BindingBuilder.bind(queue1())
        .to(directExchange()).with("warm");
    return binding;
  }

  /**
   * 把队列2绑定到交换机里面并指定队列的路由key为debug
   */
  @Bean
  public Binding binding21(){
    Binding binding= BindingBuilder.bind(queue2())
        .to(directExchange()).with("debug");
    return binding;
  }
  /**
   * 把队列2绑定到交换机里面并指定队列的路由key为error
   */
  @Bean
  public Binding binding22(){
    Binding binding= BindingBuilder.bind(queue2())
        .to(directExchange()).with("error");
    return binding;
  }

}
